{$MODE objfpc}
unit PythonStructMember;

	// Interface to map C struct members to Python object attributes

	{#include <stddef.h> /* For offsetof */

	/* The offsetof() macro calculates the offset of a structure member
	   in its structure.  Unfortunately this cannot be written down
	   portably, hence it is provided by a Standard C header file.
	   For pre-Standard C compilers, here is a version that usually works
	   (but watch out!): */

	#ifndef offsetof
	#define offsetof(type, member) ( (int) & ((type*)0) -> member )
	#endif}

	{ An array of memberlist structures defines the name, type and offset
	   of selected members of a C structure.  These can be read by
	   PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
	   is set).  The array must be terminated with an entry whose name
	   pointer is NULL.}

interface
	uses PythonObject;
	
// Types
const
	T_SHORT	= 0; {$EXTERNALSYM T_SHORT}
	T_INT		= 1; {$EXTERNALSYM T_INT}
	T_LONG	= 2; {$EXTERNALSYM T_LONG}
	T_FLOAT	= 3; {$EXTERNALSYM T_FLOAT}
	T_DOUBLE	= 4; {$EXTERNALSYM T_DOUBLE}
	T_STRING	= 5; {$EXTERNALSYM T_STRING}
	T_OBJECT	= 6; {$EXTERNALSYM T_OBJECT}
	
	// XXX the ordering here is weird for binary compatibility
	T_CHAR	= 7; {$EXTERNALSYM T_CHAR}	// 1-character string
	T_BYTE	= 8; {$EXTERNALSYM T_BYTE}	// 8-bit signed int
	// unsigned variants:
	T_UBYTE	= 9; {$EXTERNALSYM T_UBYTE}
	T_USHORT	= 10; {$EXTERNALSYM T_USHORT}
	T_UINT	= 11; {$EXTERNALSYM T_UINT}
	T_ULONG	= 12; {$EXTERNALSYM T_ULONG}

	// Added by Jack: strings contained in the structure
	T_STRING_INPLACE	= 13; {$EXTERNALSYM T_STRING_INPLACE}

	T_OBJECT_EX	= 16; {$EXTERNALSYM T_OBJECT_EX}
					// Like T_OBJECT, but raises AttributeError
				   // when the value is NULL, instead of
				   // converting to None.
	T_LONGLONG 	= 17; {$EXTERNALSYM T_LONGLONG}
	T_ULONGLONG	= 18; {$EXTERNALSYM T_ULONGLONG}

	// Flags
	READONLY	= 1; {$EXTERNALSYM READONLY}
	//define RO		READONLY		/* Shorthand */
	READ_RESTRICTED	= 2; {$EXTERNALSYM READ_RESTRICTED}
	WRITE_RESTRICTED  = 4; {$EXTERNALSYM WRITE_RESTRICTED}
	RESTRICTED	= (READ_RESTRICTED or WRITE_RESTRICTED); {$EXTERNALSYM RESTRICTED}


// Obsolete API, for binary backwards compatibility
function PyMember_Get(txt: PChar; membLst: memberlistPtr; txt1: PChar): PyObjectPtr; cdecl; external;
{$EXTERNALSYM PyMember_Get}

function PyMember_Set(txt: PChar; membLst: memberlistPtr; txt1: PChar; obj: PyObjectPtr): Integer; cdecl; external;
{$EXTERNALSYM PyMember_Set}

// Current API, use this
function PyMember_GetOne(txt: PChar; memb: PyMemberDefPtr): PyObjectPtr; cdecl; external;
{$EXTERNALSYM PyMember_GetOne}
function PyMember_SetOne(txt: PChar; memb: PyMemberDefPtr; obj: PyObjectPtr): Integer; cdecl; external;
{$EXTERNALSYM PyMember_SetOne}

implementation

end.
